import {AsyncStorage} from 'react-native'
import {createStore, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk'

import {autoRehydrate, persistStore} from 'redux-persist'
import reducers from './reducers'

const logger = store => next => action => {
	if(typeof action === 'function') console.log('dispatching a function');
	else console.log('dispatching', action);
	let result = next(action);
	console.log('next state', store.getState());
	return result;
}

const middlewares = [thunk, logger]

const store = createStore(reducers, undefined, compose(
  applyMiddleware(...middlewares),
  autoRehydrate()
))


persistStore(store, {
    whitelist : [],
    storage : AsyncStorage
}, (error, state) => {
	console.log(state, '~~~~~~~')
})

export default store